package com.lengxf.desiign;

import java.util.ArrayList;
import java.util.List;

/**
 * 容器构建类
 * By Lengxf
 */
public class Folder implements AbstractFile {

    private final List<AbstractFile> fileList = new ArrayList<>();
    private final String name;

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile abstractFile) {
        fileList.add(abstractFile);
    }

    @Override
    public void remove(AbstractFile abstractFile) {
        fileList.remove(abstractFile);
    }

    @Override
    public AbstractFile getChild(int i) {
        return fileList.get(i);
    }

    @Override
    public void killVirus() {
        System.out.println("对文件夹" + name + "进行杀毒");
        this.fileList.forEach(AbstractFile::killVirus);
    }
}
